import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv, UserConfig } from 'vite';

// 插件集合
import Plugins from './vite/plugins';
// 服务配置
import Servers from './vite/server';
// 构建配置
import Builds from './vite/build';
export default defineConfig(({ mode }) => {
	const env = loadEnv(mode, process.cwd(), '');
	return {
		// 项目根目录
		root: './',
		// 静态资源服务的文件夹
		publicDir: './public',
		plugins: Plugins,
		resolve: {
			// 路径别名
			alias: {
				'@': fileURLToPath(new URL('./src', import.meta.url)),
			},
		},
		server: Servers(env),
		css: {
			preprocessorOptions: {
				scss: {
					// 配置全局scss变量
					additionalData: '@import "@/style/variable.scss";',
				},
			},
		},
		build: Builds,
	} as UserConfig;
});
